package com.lionli.netty.demo.httpServer.server;

import com.lionli.netty.demo.httpServer.http.Request;
import com.lionli.netty.demo.httpServer.http.Response;
import com.lionli.netty.demo.httpServer.servlets.MyServlet;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.HttpRequest;

/**
 * 业务处理
 *
 * @author LionLi
 */
public class HttpHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof HttpRequest){
            HttpRequest r = (HttpRequest) msg;

            Request request = new Request(ctx,r);
            Response response = new Response(ctx,r);

            MyServlet.class.newInstance().doGet(request,response);
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {

    }
}
